﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1.DataStructure
{
    class TreeNode
    {
        public string name;
        public List<TreeNode> child;
    }


    class TestTree
    {
        static void Main()
        {
            TreeNode c = new TreeNode();
            c.name = "c";
            TreeNode d = new TreeNode();
            d.name = "d";

            #region B树
            TreeNode b = new TreeNode();
            b.name = "b";
            List<TreeNode> bChild = new List<TreeNode>();
            bChild.Add(c);
            bChild.Add(d);
            b.child = bChild;
            #endregion
            
            TreeNode e = new TreeNode();
            e.name = "e";
            List<TreeNode> eChild = new List<TreeNode>();
            TreeNode f = new TreeNode();
            f.name = "f";
            eChild.Add(f);
            e.child = eChild;

            #region A树
            TreeNode a = new TreeNode();
            a.name = "a";
            List<TreeNode> aChild = new List<TreeNode>();
            aChild.Add(b);
            aChild.Add(e);
            a.child = aChild;
            #endregion

            ForeachTree(a);
            Console.Read();
        }

        private static void ForeachTree(TreeNode node)
        {
            Console.WriteLine(node.name);
            if (node.child != null)
            {
                foreach (TreeNode t in node.child)
                {
                    ForeachTree(t);    
                }
            }
        }
    }
}
